package com.lizard.schedule.net.http.request;

import com.lizard.schedule.annotation.Request;
import com.lizard.schedule.net.http.request.bean.base.BaseRequest;

/**
 * 获取请求相关注解帮助类
 */
public class RequestAnnotationHelp {

    /**
     * HTTP请求URL
     */
    private String mUrl;

    /**
     * HTTP请求URL(调试)
     */
    private String mDebugUrl;

    /**
     * HTTP请求方法
     */
    private int mMethod;

    /**
     * response对应的bean对象类型
     */
    private Class mResponseClazz;

    public RequestAnnotationHelp(BaseRequest request) {
        obtain(request);
    }

    /**
     * 反射根据相应注解获取请求的各类信息
     *
     * @param request
     */
    private void obtain(BaseRequest request) {
        Request requestAnnotation = request.getClass().getAnnotation(Request.class);
        if (requestAnnotation != null) {
            mUrl = requestAnnotation.url();
            mDebugUrl = requestAnnotation.debugUrl();

            if (requestAnnotation.method() == Request.Method.GET) {
                mMethod = com.android.volley.Request.Method.GET;
            } else {
                mMethod = com.android.volley.Request.Method.POST;
            }

            mResponseClazz = requestAnnotation.responseClazz();
        }

    }

    /**
     * 获取HTTP请求URL(调试)
     * @return
     */
    public String getDebugUrl(){
        return mDebugUrl;
    }

    /**
     * 获取HTTP请求URL
     *
     * @return
     */
    public String getUrl() {
        return mUrl;
    }

    /**
     * 获取HTTP请求方法
     *
     * @return
     */
    public int getMethod() {
        return mMethod;
    }

    /**
     * 获取response对应的bean对象类型
     *
     * @return
     */
    public Class getResponseClazz() {
        return mResponseClazz;
    }

}
